#include "flash.h"



#include "stm32f103_reg.h"


void flash_unlock(void)
{
    FLASH->KEYR = 0x45670123;
    FLASH->KEYR = 0xCDEF89AB;
}

void flash_lock(void)
{
    FLASH->CR |= 1<<7;  // lock
}

uint8_t return_status(void)
{
    uint32_t status = FLASH->SR;

    if (status & (1<<0)) return 1;          // busy
    else if(status & (1<<2)) return 2;      //program error
    else if(status & (1<<4)) return 3;      //write protection error
    return 0;
}


